#!/bin/bash
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/sys_check.sh"
if [ -f /etc/os-release ]; then
   echo "Linux system."
elif [ -f /System/Library/CoreServices/SystemVersion.plist ]; then
   echo "macOS system."
   if [ -f ~/.bash_profile ]; then
      source ~/.bash_profile
    fi
elif current_os_is_windows; then
   echo "Windows system."
else
   echo "Unknown OS"
fi

APP_INSTALL_NAME="maxkb"
APP_TARGET_DIR_NAME="maxkb"

echo "lmdprogress:3"

source "$LMD_BASE_INSTALL_SCRIPT_DIR/apps/$APP_INSTALL_NAME/env"

export CURRENT_APP_PATH="${LMD_APPS_DIR}/${APP_TARGET_DIR_NAME}"
echo $CURRENT_APP_PATH
mkdir -p "$CURRENT_APP_PATH"

cd "$CURRENT_APP_PATH"

echo "lmdprogress:8"

if [ -d "$CURRENT_APP_PATH" ]; then
    echo "App Dir: "$CURRENT_APP_PATH
else
    echo "Error, App Dir dose not exist, please retry. "$CURRENT_APP_PATH
    exit 1
fi

echo "lmdprogress:20"

source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/docker_image_util.sh"

gen_image_repo_cpu $_DOCKER_IMAGE_NAME $_DOCKER_IMAGE_NAME_LMD $_DOCKER_IMAGE_TAG

APP_IMAGE_REPO=$APP_IMAGE_REPO_RESULT
echo "docker image repo: "$APP_IMAGE_REPO

echo "lmdprogress:50"

docker pull $APP_IMAGE_REPO


# if [ -n "$HF_ENDPOINT" ]; then
#    export HF_ENDPOINT_PARAM="-e HF_ENDPOINT=$HF_ENDPOINT"
# fi
exit_code=$?
if [ $exit_code -ne 0 ]; then
   echo $exit_code
   echo "lmdevent:docker_run_error"
   exit 1
fi

echo "lmdprogress:100"


